import 'package:syria_sports/core/app_export.dart';
import 'package:qr_flutter/qr_flutter.dart';

import '../../../widgets/app_bar/appbar_subtitle.dart';
import '../../../widgets/app_bar/custom_app_bar.dart';
import '../../../widgets/app_bar/outline_icon_button.dart';
import '../../public_home_page/bloc/public_home_screen.dart';
import 'my_qr_code_cubit.dart';
import 'package:flutter/material.dart';

class MyQrCodeScreen extends StatelessWidget {
  final String code;
  final bool isFirstScreen;
  const MyQrCodeScreen({
    Key? key,
    required this.code,
    this.isFirstScreen =false,
  }):super(key: key);

  @override
  Widget build(BuildContext context) {
    double height = MediaQuery.of(context).size.height;
    double width = MediaQuery.of(context).size.width;

    return Scaffold(
      appBar: _buildAppBar(context),
      body: BlocProvider<MyQrCodeCubit>(
        create: (context) => MyQrCodeCubit(),
        child: BlocConsumer<MyQrCodeCubit, MyQrCodeState>(
          listener: (context, state) {
            // TODO: implement listener
          },
          builder: (context, state) {
            var cubit = MyQrCodeCubit.get(context);

            return InkWell(
              onDoubleTap: (){
                if(isFirstScreen) {
                  Navigator.of(context, rootNavigator: true).pushAndRemoveUntil(MaterialPageRoute(builder: (context) =>
                const PublicHomeScreen()), (Route<dynamic> route) => false);
                }
              },
              child: SizedBox(
                height: height,
                width: width,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    if(isFirstScreen)
                    Padding(
                      padding: const EdgeInsets.only(bottom: 12.0),
                      child: Text('انقر مرتين على الشاشة للمتابعة',style: theme.textTheme.titleLarge,),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(bottom: 12.0),
                      child: Text('قم بمسح الكود التالي',style: theme.textTheme.titleLarge,),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(32.0),
                      child: QrImageView(
                        data: code,
                        version: QrVersions.auto,
                        size: 150,
                        gapless: false,
                        backgroundColor: Colors.white,
                      ),
                    ),
                  ],
                ),


              ),
            );
          },
        ),
      ),
    );
  }
  /// Section Widget
  PreferredSizeWidget _buildAppBar(BuildContext context) {

    return CustomAppBar(
      leading:(isFirstScreen)? const SizedBox(): OutlineIconButton(
        imagePath: ImageConstant.imgRightIcon,
        onTapped: (){
          Navigator.pop(context);
        },
      ),
      title: AppbarSubtitle(
        text: "الكود الشخصي".tr, margin: EdgeInsets.only(left: 12.h),
      ),
    );
  }

}
